﻿using System;
using System.Collections.ObjectModel;

namespace AppGene.DataModel
{
    /// <summary>
    /// The collection class for LogicalIndex.
    /// </summary>
    public class LogicalIndexCollection
        : KeyedCollection<string, LogicalIndex>
    {
        /// <summary>
        /// Creates a logical index collection instance.
        /// </summary>
        public LogicalIndexCollection()
            : base(StringComparer.OrdinalIgnoreCase)
        { }

        /// <summary>
        /// Gets the key for a logical index instance.
        /// </summary>
        /// <param name="item">The logical index.</param>
        /// <returns>Returns the key for a logical index instance.</returns>
        protected override string GetKeyForItem(LogicalIndex item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            string key = "";
            foreach (var column in item.Columns)
            {
                key += "_" + column.Name;
            }
            if (key.Length>0)
            {
                key = key.Substring(1);
            }
            return key;
        }
    }
}

